package cn.lanqiao.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;
import cn.lanqiao.entity.Course;



public class TeacherUpdateCourseFrm extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
    private JTable table;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			TeacherUpdateCourseFrm dialog = new TeacherUpdateCourseFrm();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 * @param course 
	 */
	 public TeacherUpdateCourseFrm(Course updateCourse) {
		 this();
	     this.textField.setText(updateCourse.getCid());
	     this.textField_1.setText(updateCourse.getCname());
	     this.textField_2.setText(updateCourse.getCteaher());
	     this.textField_3.setText(updateCourse.getCexam());
	 }
	 public TeacherUpdateCourseFrm(Course update,JTable table) {
		 this();
	     this.textField.setText(update.getCid());
	     this.textField_1.setText(update.getCname());
	     this.textField_2.setText(update.getCteaher());
	     this.textField_3.setText(update.getCexam());
	     this.table=table;
	 }
	 
	 
	public TeacherUpdateCourseFrm() {
		setBounds(100, 100, 532, 350);
		this.setLocationRelativeTo(null);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		
		JButton btnNewButton = new JButton("课程编号");
		btnNewButton.setBounds(32, 39, 113, 27);
		contentPanel.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("课程名称");
		btnNewButton_1.setBounds(32, 112, 113, 27);
		contentPanel.add(btnNewButton_1);
		
		JButton btnNewButton_2 = new JButton("任课教师");
		btnNewButton_2.setBounds(32, 178, 113, 27);
		contentPanel.add(btnNewButton_2);
		
		JButton btnNewButton_3 = new JButton("考试时间");
		btnNewButton_3.setBounds(32, 253, 113, 27);
		contentPanel.add(btnNewButton_3);
		
		textField = new JTextField();
		textField.setBounds(255, 40, 123, 26);
		contentPanel.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(255, 113, 123, 26);
		contentPanel.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(255, 179, 123, 26);
		contentPanel.add(textField_2);
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(255, 254, 123, 26);
		contentPanel.add(textField_3);
		textField_3.setColumns(10);
		
		JButton btnNewButton_4 = new JButton("保存修改");
		btnNewButton_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//创建一个新文本框;
				String cid=textField.getText();
				String cname=textField_1.getText();
				String cteacher=textField_2.getText();
				String cexam=textField_3.getText();
				
			
				//封装成一个新的对象
				Course course=new Course(cid,cname,cteacher,cexam);
				//调业务层
				cn.lanqiao.service.CourseService service=new cn.lanqiao.service.impl.CourseServiceImpl();
				service.update(cid, course);
				TeacherUpdateCourseFrm.this.dispose();
				//刷新
				Object[][] datas = service.list();
				String[] string=new String[] {"\u7F16\u53F7", "\u5B66\u53F7", "\u6210\u7EE9","\u8003\u8BD5"
				};
				table.setModel(new DefaultTableModel(datas,string));
				}
		});
		btnNewButton_4.setBounds(392, 86, 122, 51);
		contentPanel.add(btnNewButton_4);
		
		JButton btnNewButton_5 = new JButton("取消");
		btnNewButton_5.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//关闭
				TeacherUpdateCourseFrm.this.dispose();
			}
		});
		btnNewButton_5.setBounds(392, 178, 122, 51);
		contentPanel.add(btnNewButton_5);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
		}
	}
	
}
